package com.wandian.setting.adapter;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.mylib.libcore.AppContext;
import com.mylib.libcore.bean.UserInfoBean;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.utils.GlideUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.setting.R;
import com.wandian.setting.bean.DynamicDataBean;


/**
 * @author Administrator
 * @date 2019/12/16-13:32
 * @description UserInfoDTRecycleAdapter
 **/
public class UserInfoDTRecycleAdapter extends BaseQuickAdapter<DynamicDataBean, BaseViewHolder> {
    private String user_head;
    private String user_name;
    private int number = 0;
    private String isMine;
    private UserInfoBean userInfoBean = AppContext.getInstance().getAppPreferencesHelper().getUserInfoBean();
    private DeleteClink deleteClink;

    private DeleteClink getDeleteClink() {
        return deleteClink;
    }

    public void setDeleteClink(DeleteClink deleteClink) {
        this.deleteClink = deleteClink;
    }

    public interface DeleteClink{
        void deleteId(String id,int index);
    }


    public UserInfoDTRecycleAdapter(int layoutResId,String isMine,String user_head,String user_name ) {
        super(layoutResId);
        this.isMine = isMine;
        this.user_head = user_head;
        this.user_name = user_name;
    }


    @Override
    protected void convert(BaseViewHolder helper, DynamicDataBean item) {
        TextView tv_user_name = helper.getView(R.id.tv_user_name);
        tv_user_name.setText(user_name+"");
        RoundedImageView iv_head = helper.getView(R.id.iv_head);
        GlideUtil.loadhead(mContext,user_head,iv_head);
        TextView tv_dz_number = helper.getView(R.id.tv_dz_number);
        tv_dz_number.setText(number+"");
        TextView tv_dt_text = helper.getView(R.id.tv_dt_text);
        tv_dt_text.setText(item.getContent()+"");
        TextView tv_dt_time = helper.getView(R.id.tv_dt_time);
        tv_dt_time.setText(UIUtils.showTimeByString(item.getCreateTime())+"");
        TextView tv_dt_time_data = helper.getView(R.id.tv_dt_time_data);
        tv_dt_time_data.setText(UIUtils.showDataByString(item.getCreateTime())+"");


        helper.getView(R.id.ll_message).setOnClickListener(v -> ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_SETTING_MY_EVALUATE).navigation());
        helper.getView(R.id.ll_dz).setOnClickListener(v -> {
            number++;
            tv_dz_number.setText(number+"");
        });
        ImageView iv_delete = helper.getView(R.id.iv_delete);
        iv_delete.setOnClickListener(v -> deleteClink.deleteId(item.getId(),helper.getLayoutPosition()));
        if(!UIUtils.isEmpty(isMine) && isMine.equals("0")){
            iv_delete.setVisibility(View.GONE);
        }else {
            iv_delete.setVisibility(View.VISIBLE);
        }
        LinearLayout ll_dt_pics = helper.getView(R.id.ll_dt_pics);
        ImageView iv_dt_pic_1 = helper.getView(R.id.iv_dt_pic_1);
        ImageView iv_dt_pic_2 = helper.getView(R.id.iv_dt_pic_2);
        ImageView iv_dt_pic_3 = helper.getView(R.id.iv_dt_pic_3);
        if(!UIUtils.isEmpty(item.getImgList()) && item.getImgList().size()>0 && !UIUtils.isEmpty(item.getImgList().get(0))){
            ll_dt_pics.setVisibility(View.VISIBLE);
            //获取图片真正的宽高
            for(int i=0;i<item.getImgList().size();i++){
                switch (i){
                    case 0:
                        setItemImageView(iv_dt_pic_1,item.getImgList().get(i));
                        break;
                    case 1:
                        setItemImageView(iv_dt_pic_2,item.getImgList().get(i));
                        break;
                    case 2:
                        setItemImageView(iv_dt_pic_3,item.getImgList().get(i));
                        break;
                }
            }

        }else {
            ll_dt_pics.setVisibility(View.GONE);
        }
    }

    private  void  setItemImageView(ImageView iv_item_pic,String imgPath){
        if(UIUtils.isEmpty(imgPath))return;
        iv_item_pic.setVisibility(View.VISIBLE);
        GlideUtil.loadImgAutoSize(mContext,imgPath,iv_item_pic);
        iv_item_pic.setOnClickListener(v -> {
            if(!UIUtils.isEmpty(imgPath)){
                Bundle bundle = new Bundle();
                bundle.putString("file_type","pic");
                bundle.putString("file_path",imgPath);
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_CHECK_FILE).with(bundle).navigation();
            }
        });
    }
}
